﻿// <copyright file="ProfileConverter.cs" company="Microsoft Corporation">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-03-03</date>
// <summary>A Value Converter</summary>

namespace NYTimes.ValueConverters
{
    using System;
    using System.Windows.Data;
    using NYTimes.Data;

    /// <summary>
    /// A Value converter to get New York Times TimesPeople Profile data from a User 
    /// id
    /// </summary>
    public class ProfileConverter : IValueConverter
    {
        /// <summary>
        /// Gets or sets the TimesPeople API key
        /// </summary>
        public string ApiKey { get; set; }

        #region IValueConverter Members

        /// <summary>
        /// Modifies the source data before passing it to the target for display in the UI. 
        /// </summary>
        /// <param name="value">a <see cref="NYTimes.Data.Profile"/> object with a valid UserId value.</param>
        /// <param name="targetType">The Type of data expected by the target dependency property.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>a <see cref="NYTimes.TimesPeopleProfile"/> object that is querying for profile data about the user.</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var inputProfile = value as Profile;

            var profile = new TimesPeopleProfile(inputProfile)
            {
                UserId = inputProfile.UserId
            };

            if (!string.IsNullOrEmpty(this.ApiKey))
            {
                profile.ApiKey = this.ApiKey;
            }

            return profile;
        }

        /// <summary>
        /// Not implemented
        /// </summary>
        /// <param name="value">The target data being passed to the source.</param>
        /// <param name="targetType">The Type of data expected by the source object.</param>
        /// <param name="parameter">An optional parameter to be used in the converter logic. </param>
        /// <param name="culture">The culture of the conversion.</param>
        /// <returns>The value to be passed to the source object.</returns>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
